/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.nextel.ui;

import com.nextel.ui.custom.OTextDecimalListener;
import javax.microedition.lcdui.Canvas;

/**
 *
 * @author Victor Laguna <vlaguna@dsbmobile.com>
 */
public class OEditableCell extends OCell  {
/**
   * Constructor used to allocate an OCell object.
   * The default OCell renderer shall be used by
   * the {@link com.nextel.ui.OGrid} component.
   * This constructor is the preferred way to
   * create OCell objects.
   *
   * @param v Contains the OCell object value.
   */
   public OEditableCell(Object v)
   {
       super(v);
   }

    public void keyPressed(int keyCode) {
        
        char c = (char)keyCode;
        
//        System.out.println("OEditableCell.keyPressed w/keyCode= " + c);
        
        if(c>='0' && c<='9'){
            this.value = ((String)this.value) + c;
        }
        else if(c==Canvas.KEY_STAR || keyCode == 8 ){
            String s = (String)this.value;
            if(s.length()>0){
                s = s.substring(0,s.length()-1);
                this.value = s;
            }
        }else if(c == '.'){
            if(((String)this.value).indexOf('.') == -1){
                keyPressed(Canvas.KEY_STAR);
                this.value = ((String)this.value) + c;
               
            }
        }
            
        
   }
    
   
    
}
